package com.zmy.xcx.controller;

import com.zmy.xcx.common.convention.result.Result;
import com.zmy.xcx.common.convention.result.Results;
import com.zmy.xcx.dao.entity.HyperglycemiaMedication;
import com.zmy.xcx.service.HyperglycemiaMedicationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/hyperglycemia-medication")
public class HyperglycemiaMedicationController {

    private final HyperglycemiaMedicationService hyperglycemiaMedicationService;

    @PostMapping("/clicks/{id}")
    public void incrementPageView(@PathVariable("id") Integer id) {
        hyperglycemiaMedicationService.incrementPageView(id);
    }

    /**
     * 根据id查询高血糖药品
     *
     * @param id 高血糖药品ID
     * @return 高血糖药品信息
     */
    @GetMapping("/{id}")
    public Result<HyperglycemiaMedication> getHyperglycemiaMedication(@PathVariable("id") Long id) {
        HyperglycemiaMedication hyperglycemiaMedication = hyperglycemiaMedicationService.getHyperglycemiaMedication(id);
        return Results.success(hyperglycemiaMedication);
    }

    /**
     * 根据药品名称drugName查询高血糖药品
     *
     * @param drugName 药品名称
     * @return 高血糖药品信息
     */
    @GetMapping("/name/{drugName}")
    public Result<HyperglycemiaMedication> getHyperglycemiaMedicationByDrugName(@PathVariable("drugName") String drugName) {
        HyperglycemiaMedication hyperglycemiaMedication = hyperglycemiaMedicationService.getHyperglycemiaMedicationByDrugName(drugName);
        return Results.success(hyperglycemiaMedication);
    }

}
